package PTOP.ptopjms;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

import javax.jms.*;

public class Producer {

    public static String BROKER_URL = "tcp://0.0.0.0:61616";
    public static String USER = "admin";
    public static String PASSWORD = "admin";
    public static String DESITNATION = "SystemA.SystemB.Queue";
    public static void main(String[] args) throws JMSException {
        //创建连接工厂
        ConnectionFactory factory = new ActiveMQConnectionFactory(BROKER_URL);
        //创建连接
        Connection connection = factory.createConnection(USER,PASSWORD);
        //创建会话
        Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        //创建消息
        TextMessage textMessage = session.createTextMessage("MQ test");
        //消息目的地
        Destination destination = new ActiveMQQueue(DESITNATION);
        //发送消息
        MessageProducer producer = session.createProducer(destination);
        producer.send(textMessage);
        System.out.println("message send");

        //释放资源
        session.close();
        connection.close();
        System.exit(0);
    }
}
